from typing import Optional
from model.uml_element import UmlElement
from model.uml_type import UmlType
from model.uml_value import UmlValue
from model.uml_xmi_info import UmlXmiInfo


class UmlParameter(UmlElement):
    def __init__(self) -> None:
        super().__init__(UmlXmiInfo.type_parameter)
        self.name: str = ""
        self.isOrdered: str = ""
        self.isUnique: str = ""
        self.direction: str = ""
        self.type: Optional[UmlType] = None
        self.upperValue: Optional[UmlValue] = None
        self.lowerValue: Optional[UmlValue] = None

    def to_json(self) -> dict[str, object]:
        json: dict = super().to_json()
        json["name"] = self.name
        json["isOrdered"] = self.isOrdered
        json["isUnique"] = self.isUnique
        json["direction"] = self.direction

        if self.type is not None:
            json["type"] = self.type.to_json()
        if self.lowerValue is not None:
            json["lowerValue"] = self.lowerValue.to_json()
        if self.upperValue is not None:
            json["upperValue"] = self.upperValue.to_json()

        return json
